<?php

ini_set('SMTP', $smtp);
ini_set('sendmail_from', 'helpdesk@'.$company.'.com');
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0;' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1;' . "\n";
// Additional headers
$headers .= 'To: ;' . "\n";
$headers .= 'From: '.$title.' <vhs@'.$company.'.com>;' . "";
$Name = $company; //senders name
$email = 'helpdesk@'.$company.'.com'; //senders e-mail adress


$result = mysql_query("SELECT * FROM tblUsers where Name = '$_POST[assigned]' ");
$rows = mysql_fetch_array($result);

$recipient = $rows[Email]; //recipient
#echo 'To:'.$recipient ;
switch ($_POST[mail])
{
case('new');

$recipient=$emailgroup;
if($problem=='')
 {
$mail_body = '
<center>'.$title.'</center>

<br>new Job Generated
<br>Job Number:<b> '.$Log.'</b> http://'.$ip.'/index.php?p=hupdate&log='.$Log.'"

<br><b>Operator :</b> '.$user.'
<br><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject : </b>  '.$_POST[subject].'
<br><b>Problem : </b>
<p>'.nl2br($_POST[problem]).'





<p><p>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
 }
 else
 {
  $mail_body = '
<center>'.$title.'</center>

<br>new Job Generated
<br>Job Number:<b> '.$Log.'</b> http://'.$ip.'/index.php?p=hupdate&log='.$Log.'"

<br><b>Operator :</b> '.$user.'
<br><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject : </b>  '.$subject.'
<br><b>Problem : </b>
<p>'.nl2br($problem).'





<p><p>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
 }
$mailsubject = 'VHS new job generated'; //subject
if($itemails=='true')
{
mail($recipient, $mailsubject, $mail_body, $headers);


}
$recipient=$_POST[mailupdates];

if($problem=='')
    {
$mail_body = '
<center>'.$title.'</center>

<br>new Job Generated
<br>Job Number: <b>'.$Log.'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$Log.'"


<p><b>Requestor :</b> '.$_POST[requestor].'
<br><b>Subject : </b>  '.$_POST[subject].'
<br><b>Problem : </b>
<p>'.nl2br($_POST[problem]).'

<br><br>see all jobs in progress :
<br>(public view) http://'.$ip.'/helpdesk/dashboard.php


<p>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
    }
    else
        {
        $mail_body = '
<center>'.$title.'</center>

<br>new Job Generated
<br>Job Number: <b>'.$Log.'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$Log.'"


<p><b>Requestor :</b> '.$_POST[requestor].'
<br><b>Subject : </b>  '.$subject.'
<br><b>Problem : </b>
<p>'.nl2br($problem).'



<br><br>see all jobs in progress :
<br>(public view) http://'.$ip.'/helpdesk/dashboard.php


<p>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
        }
$mailsubject = 'VHS new job generated'; //subject
if($publicemails=='true' & $_POST[mailupdates]!='')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}

break;

case('closed');


$mail_body = '
<center><h1>'.$title.'</h1></center>

<br><h2>The below job has been closed</h2>
<br><b>Job Number: '.$_GET[log].'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$_GET[log].'"

<p><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject :</b>   '.$_POST[subject].'
<br><b>Problem : </b><p>  '.nl2br($_POST[problem]).'
<p><b>Solution :</b>
<p>';
$result = mysql_query("SELECT * FROM tblSolutions where LogNumber='$log' ORDER BY `key` DESC");

$mail_body .= '<table border=1 Width="100%"><tr><td>Date</td><td>Time</td><td>Operator</td><td>Solution</td><td>Time Spent</TD>';
while($row = mysql_fetch_array($result))
{
$mail_body .= '<tr><td>'.$row['Date'].'</td><td>'.$row['Time'].'</td><td>'.$row['Operator'].'</td><td>'.nl2br($row['Solution']).'</td><td>'.$row['TimeS'].'</tr>';
$total=$row[TimeS]+$total;

}
$mail_body .='</table> <br> <b>Total Time : </b>'.$total.' Mins';

$mail_body .= '<br><br>see all jobs in progress http://'.$ip.'/VHS/helpdesk/dashboard.php
<br>If you need to get an update on a loged call please check by clicking on the log number above or call 1220 or 01752 636350

<br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job Closed'; //subject
if($itemails=='true' & $_POST[assigned]!='Not Assigned')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}

$recipient=$_POST[mailupdates];

$mail_body1 = '
<center><h1>'.$title.'</h1></center>

<br><h2>The below job has been closed</h2>
<br><b>Job Number: '.$_GET[log].'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$_GET[log].'"

<p><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject :</b>   '.$_POST[subject].'
<br><b>Problem : </b><p>  '.nl2br($_POST[problem]).'
<p><b>Solution :</b>
<p>';
$result = mysql_query("SELECT * FROM tblSolutions where LogNumber='$log' ORDER BY `key` DESC");

$mail_body1 .= '<table border=1 Width="100%"><tr><td>Date</td><td>Time</td><td>Operator</td><td>Solution</td><td>Time Spent</TD>';
while($row = mysql_fetch_array($result))
{
$mail_body1 .= '<tr><td>'.$row['Date'].'</td><td>'.$row['Time'].'</td><td>'.$row['Operator'].'</td><td>'.nl2br($row['Solution']).'</td><td>'.$row['TimeS'].'</tr>';
$total=$row[TimeS]+$total;

}
$mail_body1 .='</table> <br> <b>Total Time : </b>'.$total.' Mins';

$mail_body1 .= '<br><br>see all jobs in progress http://'.$ip.'/VHS/helpdesk/dashboard.php
<br>If you need to get an update on a loged call please check by clicking on the log number above or call 1220 or 01752 636350

<br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job Closed'; //subject
if($publicemails=='true' & $_POST[mailupdates]!='')
{
mail($recipient, $mailsubject, $mail_body1, $headers);


}
break;
case('reopened');


$mail_body = '
<center><h1>'.$title.'</h1></center>

<br><h2>The below job has been reopened</h2>
<br><b>Job Number: '.$_GET[log].'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$_GET[log].'"

<p><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject :</b>   '.$_POST[subject].'
<br><b>Problem : </b><p>  '.nl2br($_POST[problem]).'
<p><b>Solution :</b>
<p>';
$result = mysql_query("SELECT * FROM tblSolutions where LogNumber='$log' ORDER BY `key` DESC");

$mail_body .= '<table border=1 Width="100%"><tr><td>Date</td><td>Time</td><td>Operator</td><td>Solution</td><td>Time Spent</TD>';
while($row = mysql_fetch_array($result))
{
$mail_body .= '<tr><td>'.$row['Date'].'</td><td>'.$row['Time'].'</td><td>'.$row['Operator'].'</td><td>'.nl2br($row['Solution']).'</td><td>'.$row['TimeS'].'</tr>';
$total=$row[TimeS]+$total;

}
$mail_body .='</table> <br> <b>Total Time : </b>'.$total.' Mins';

$mail_body .= '<br><br>see all jobs in progress http://'.$ip.'/VHS/helpdesk/dashboard.php
<br>If you need to get an update on a loged call please check by clicking on the log number above or call 1220 or 01752 636350

<br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job reopened'; //subject
if($itemails=='true' & $_POST[assigned]!='Not Assigned')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}

$recipient=$_POST[mailupdates];

$mail_body1 = '
<center><h1>'.$title.'</h1></center>

<br><h2>The below job has been reopened</h2>
<br><b>Job Number: '.$_GET[log].'</b> http://'.$ip.'/helpdesk/publicview.php?l='.$_GET[log].'"

<p><b>Requestor : </b>'.$_POST[requestor].'
<br><b>Subject :</b>   '.$_POST[subject].'
<br><b>Problem : </b><p>  '.nl2br($_POST[problem]).'
<p><b>Solution :</b>
<p>';
$result = mysql_query("SELECT * FROM tblSolutions where LogNumber='$log' ORDER BY `key` DESC");

$mail_body1 .= '<table border=1 Width="100%"><tr><td>Date</td><td>Time</td><td>Operator</td><td>Solution</td><td>Time Spent</TD>';
while($row = mysql_fetch_array($result))
{
$mail_body1 .= '<tr><td>'.$row['Date'].'</td><td>'.$row['Time'].'</td><td>'.$row['Operator'].'</td><td>'.nl2br($row['Solution']).'</td><td>'.$row['TimeS'].'</tr>';
$total=$row[TimeS]+$total;

}
$mail_body1 .='</table> <br> <b>Total Time : </b>'.$total.' Mins';

$mail_body1 .= '<br><br>see all jobs in progress http://'.$ip.'/VHS/helpdesk/dashboard.php
<br>If you need to get an update on a loged call please check by clicking on the log number above or call 1220 or 01752 636350

<br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job reopened'; //subject
if($publicemails=='true' & $_POST[mailupdates]!='')
{
mail($recipient, $mailsubject, $mail_body1, $headers);


}
break;


case('updated');
if ($_POST[assigned]!=$user & $_POST[assigned]!='Not Assigned')
{
    $mail_body = '

<center>'.$title.'</center>

<br>Job Updated
<br>Job Number: '.$_GET[log].' http://'.$ip.'/index.php?p=hupdate&log='.$_GET[log].'"

<br>Operator : '.$user.'

<br>Solution :
<br>
'.$_POST[solution].'

<br><br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job updated'; //subject
if($itemails=='true')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}
}

$recipient=$_POST[mailupdates];

$mail_body = '

<center>'.$title.'</center>

<br>Job Updated
<br>Job Number: '.$_GET[log].' http://'.$ip.'/helpdesk/publicview.php?l='.$_GET[log].'"

<br>Operator : '.$user.'

<br>Solution :
<br><br>
'.$_POST[solution].'

<p>message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job updated'; //subject
if($publicemails=='true' & $_POST[mailupdates]!='')
{
#mail($recipient, $mailsubject, $mail_body, $headers);
}
break;

case('assigned');
$mail_body = '
<center>'.$title.'</center>

<br>new Job has been assigned to you
<br>Job Number: '.$_GET[log].' http://'.$ip.'/index.php?p=hupdate&log='.$_GET[log].'"

<br>Assigned by : '.$user.'



<br><br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job Assigned'; //subject

if($itemails=='true' & $_POST[assigned]!='Not Assigned')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}

$recipient=$_POST[mailupdates];
$mail_body = '
<center>'.$title.'</center>

<br>your Job has been assigned to a member of the IT team
<br>Job Number: '.$_GET[log].' http://'.$ip.'/index.php?p=hupdate&log='.$_GET[log].'"

<br>Assigned to : '.$_POST[assigned].'



<br><br>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS job Assigned'; //subject
if($publicemails=='true' & $_POST[mailupdates]!='' & $_POST[assigned]!='Not Assigned')
{
mail($recipient, $mailsubject, $mail_body, $headers);
}
break;

case('kbcheckin');

$recipient=$emailgroup;
$mail_body = '
<center>'.$title.'</center>

<br>Kb document updated
<br>Document number:<a href="http://'.$ip.'/kb/documents/'.$docname.'"<b>'.$_GET[doc].'</b></a>

<br><b>Operator :</b> '.$user.'
<br><b>Change : </b>'.$_POST[change].'
<br><b>Document name </b>'.$docname.'





<p><p>Message generated by VHS server on behalf of '.$company.' IT Department please do not reply to this message

<br>Thank you '; //mail body
$mailsubject = 'VHS KB document updated'; //subject

if($itemails=='true')
{
mail($recipient, $mailsubject, $mail_body, $headers);


}
break;
}




?>